home *** CD-ROM | disk | FTP | other *** search
- Path: news.compuserve.com!newsmaster
- From: Philippe Verdy <100105.3120@compuserve.com>
- Newsgroups: comp.lang.c++
- Subject: Re: Is this possible?
- Date: 24 Mar 1996 01:01:26 GMT
- Organization: CompuServe Incorporated
- Message-ID: <4j26t6$shm@arl-news-svc-3.compuserve.com>
- NNTP-Posting-Host: ad53-232.compuserve.com
-
- Sensarn <txs53132@bayou.uh.edu> s'Θcrit :
- > Is it possible to use NEW for FAR memory allocation in the SMALL
- > memory model? I get NULL POINTER ASSIGNMENT when I try this using
- > farmalloc() for my FAR allocation:
- >
- > unsigned char **ptr; /* Pointer to unsigned char pointers */
- > ptr=(unsigned char far **)farmalloc(1); /* Create a pointer */
- > ptr[0]=(unsigned char far *)farmalloc(64001); /* Allocate memory */
- >
- > I want to create an array of pointers -- each pointing to 64016 bytes --
- > I get NULL POINTER ASSIGNMENT instead. I tried this:
- >
- > unsigned char far **ptr;
- > ptr=new unsigned char far *[1];
- > ptr[0]=new unsigned char far[64001];
- >
- > I got no errors -- except for the fact that I didn't have enough NEAR
- > heap for the allocation. Please try to help me,
- >
- > --
- > ______________________________
- >
- > Steven Sensarn
- > E-Mail - txs53132@bayou.uh.edu
- > ______________________________
-
- When you call : (new T), the result is a (T*) and not a
- (T far *). There is no support for a _farnew operator.
-
- You can obtain such a result using the placement arguments
- for the new operator, or using class specific implementation
- eg:
-
- class farheap {
- public:
- static void far * operator new(size_t sz) throw xalloc;
- static operator delete(void far *);
- };
-
- void far * farheap::operator new(size_t sz) throw xalloc
- {
- void far *p = farmalloc(sz);
- if (!p) throw xalloc(sz);
- return p;
- }
-
- void farheap::operator delete(void far *p)
- {
- if (p) farfree(p);
- }
-
- Then derive your far-allocated classes from this class, or use
- farheap::new and farheap::delete explicitly:
-
- char far *p = farheap::new char far[1000];
- ...
- farheap::delete p;
-
- As an alternative, you can also use the placement argument to
- build specific memory allocation algorithms using
- memory pool classes of your own (for example using the Windows
- Global memory pool, or the DDE shared memory pool, or a
- file mapped in memory allocation used as a fast private
- swap area)... The mechanism of constructors will still apply
- while using different memory allocation schemes for objects!
-